package com.chaidb;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import com.db.DbConnection;
public class AddMarker {
	
	@SuppressWarnings({ "finally", "unchecked" })
	public HashMap doAddMarker(Object Marker,String userid,String type)
	{
		HashMap result = null;
		result = new HashMap();
		System.out.println("I am here in add marker");
		
		String createsql = "insert into marker(userid,description,latitude," +
				"longitude,markername,type)values('" + userid + "','" 
			+ ((HashMap)Marker).get("description") + "','" +((HashMap)Marker).get("latitude")  + "','" +
			((HashMap)Marker).get("longitude") + "','" + ((HashMap)Marker).get("markername") + "','" + 
			((HashMap)Marker).get("type")  + "');";
		System.out.println(createsql);
		
		Connection con = null;
		ArrayList markers = null;
		MyMarker marker = null;
		try {
			con = DbConnection.getInstance().getConnection();
			Statement st = con.createStatement();
			int rs = st.executeUpdate(createsql);
			if(rs == 1)
			{
				if(type.equals("myown"))
				{
					ShowAllMyMarker dd = new ShowAllMyMarker();
					markers = dd.doShowAllMyMarker(userid);
				}else
				{
					ShowTypeMarkers dd = new ShowTypeMarkers();
					markers = dd.doShowTypeMarkers(type);
				}
				GetAMarker get = new GetAMarker();
				marker = get.doGetMarker((String)((HashMap)Marker).get("markername"), userid);
			}
		}catch(SQLException e)
		{
			e.printStackTrace();
		}finally
		{
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
			result.put("marker", marker);
			result.put("markers", markers);
			return result;
		}
	}

}
